package com.chenliwu.demo.json;

import com.chenliwu.demo.json.utils.JsonUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenlw
 * @since 2020-06-29
 */
public class JackSonTest {

    public static void main(String[] args) {
        testJsonTransfer();
    }

    public static void testMapToJsonString() {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("key1", "key1");
        dataMap.put("key2", "key2");
        dataMap.put("key3", "key3");
        dataMap.put("key4", "key4");
        Map<String, Object> approveConfigs = new HashMap<>();
        approveConfigs.put("op", "op");

        dataMap.put("approveConfigs", approveConfigs);
        System.out.println(JsonUtils.toJSONString(dataMap));
    }

    static void testJsonTransfer() {
        Staff staff = new Staff();
        staff.setName("name1");
        staff.setSex("sex");
        staff.setDetName("detName1");

        System.out.println(JsonUtils.toJSONString(staff));
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    private static class Staff {

        private String name;

        private String sex;

        /**
         * 部门名称
         */
        @JsonProperty("det_name")
        private String detName;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public String getDetName() {
            return detName;
        }

        public void setDetName(String detName) {
            this.detName = detName;
        }
    }

}
